package com.dream.technology.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.dream.technology.db.entity.RcRuleItem;
import com.dream.technology.db.entity.RcRuleItemQuery;
import com.dream.technology.data.GenericRspDTO;
import com.dream.technology.service.RcRuleItemService;
import com.dream.technology.vo.ErrorCode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/risk/admin/rule_item")
public class RcRuleItemController {

    private static final Logger logger = LoggerFactory.getLogger(RcRuleItemController.class);


    @Autowired
    RcRuleItemService rcRuleItemService;

    /**
     * 风控规则配置项接口
     * @param pageNum
     * @param pageSize
     * @param ruleItem_alias
     * @return
     */
    @GetMapping("/list")
    public GenericRspDTO<Object> getList(Integer pageNum, Integer pageSize, String ruleItem_alias){

        RcRuleItemQuery rcRuleItemQuery =new RcRuleItemQuery();
        PageHelper.startPage(pageNum,pageSize);
        List<RcRuleItem> rcRuleItemList = rcRuleItemService.selectByExample(rcRuleItemQuery);
        PageInfo pageInfo=new PageInfo(rcRuleItemList);

        return GenericRspDTO.newInstance(ErrorCode.SUCCESS.getErrorCode(), ErrorCode.SUCCESS.getErrorMsg(), pageInfo);
    }

    /**
     * 风控规则配置项回显接口
     * @param id
     * @return
     */
    @GetMapping("/id")
    public GenericRspDTO<Object> getById(Long id){

        RcRuleItem rcRuleItem = rcRuleItemService.selectByPrimaryKey(id);

        return GenericRspDTO.newInstance(ErrorCode.SUCCESS.getErrorCode(), ErrorCode.SUCCESS.getErrorMsg(), rcRuleItem);
    }

    /**
     * 添加风控规则配置项
     * @param rcRuleItem
     * @return
     */
    @PostMapping("/add")
    public GenericRspDTO<Object> add(RcRuleItem rcRuleItem){

        rcRuleItemService.insert(rcRuleItem);

        return GenericRspDTO.newInstance(ErrorCode.SUCCESS.getErrorCode(), ErrorCode.SUCCESS.getErrorMsg(), null);
    }

    /**
     * 修改风控规则配置项
     * @param rcRuleItem
     * @return
     */
    @PostMapping("/update")
    public GenericRspDTO<Object> update(RcRuleItem rcRuleItem){

        rcRuleItemService.updateByPrimaryKeySelective(rcRuleItem);

        return GenericRspDTO.newInstance(ErrorCode.SUCCESS.getErrorCode(), ErrorCode.SUCCESS.getErrorMsg(), null);
    }

    /**
     * 删 删除风控规则配置项 (逻辑删除)
     * @param id
     * @return
     */
    @PostMapping("/delete")
    public GenericRspDTO<Object> delete(Long id){

        rcRuleItemService.deleteByPrimaryKey(id);

        return GenericRspDTO.newInstance(ErrorCode.SUCCESS.getErrorCode(), ErrorCode.SUCCESS.getErrorMsg(), null);
    }


}
